
var app = getApp()
var maxTime = 60 
var interval = null 
var currentTime = -1 //倒计时的事件（单位：s）  
var server = require('../../utils/server');
Page({
	data: {
		login:false,
    time:'获取验证码',
    countDownNum: 60,
    mobile:'',
    num:'',
    num1:'',
    pass:'',
    remindpass:'',
    area:'',
    region: ['', '', ''],
	},
	onLoad: function (options) {
    currentTime = -1;
    var that = this;
    wx.getSystemInfo({
        success: function(res) {
            that.setData({height:res.windowHeight})
        }
    })
	},
  //倒计时
  countDown: function () {
    let that = this;
    let countDownNum = that.data.countDownNum;
    that.setData({
      timer: setInterval(function () {
        countDownNum--;
        that.setData({
          time: countDownNum + 's'
        })
        if (countDownNum == 0) {
          clearInterval(that.data.timer);
          that.setData({
            time: '获取验证码'
          })
        }
      }, 1000)
    })
  },
  //手机号
  getPhoneNum:function(e){
    this.setData({
      mobile: e.detail.value,
    });
  },
//获取验证码
  getnum: function (e) {
    var that = this;
    let _params={
        mobile: that.data.mobile,
        type: ''
    }
    if (_params.mobile.length==11){
        // server.postJSON('/user/sendsms',_params,(res)=>{
        //     console.log(res)
        //   that.countDown()
        //     that.setData({
        //       num1:res.data.list.code
        //     });
        //     wx.showToast({
        //       title: res.data.msg,
        //       icon: 'none'
        //     });
        // })
        server.send('/user/sendsms', 'POST',_params).then (res=> {
            that.countDown()
            that.setData({
                num1: res.list.code
            });
            wx.showToast({
                title: res.msg,
                icon: 'none'
            });
        })
    }
    else{
        wx.showToast({
          title: '手机号格式错误！',
          icon: 'none'
        })
    }
    
  },
  //验证码
  inputNum: function (e) {
    // this.data.num = e.detail.value;
    this.setData({
      num: e.detail.value,
    });
  },
  //密码
  inputPass: function (e) {
    this.setData({
      pass: e.detail.value,
    });
  },
  //确认密码
  inputRemindPass: function (e) {
    this.setData({
      remindpass: e.detail.value,
    });
  },
  inputarea:function(e){
    
    this.setData({
      area: e.detail.code[2],
      region: e.detail.value
    });
    console.log(this.data.area)
  },
  //注册
  quick_register_phone: function (e) {
    let that = this
    let num = that.data.num
    let num1 = that.data.num1
    let pass = that.data.pass
    let remindpass= that.data.remindpass
    let area = that.data.area
    let _params={
            mobile: that.data.mobile,
            password: pass,
            password1: remindpass,
            area: area
    }
    if (num == num1){
      if (pass == remindpass){
        //   server.postJSON('/user/reg', _params, (res) => {
        //       wx.showToast({
        //         title: res.data.msg,
        //         icon: 'none'
        //       })
        //   })
          server.send('/user/reg', 'POST',_params).then (res => {
              wx.showToast({
                  title: res.msg,
                  icon: 'none'
              })
          })
      }else{
          wx.showToast({
            title: '两次密码不一致！',
            icon: 'none'
          })
      }
    }else {
      wx.showToast({
        title: '验证码错误！',
        icon: 'none'
      })
    }
   
  },
})



